import React, {Component} from 'react';
import {connect} from 'dva';
import {routerRedux} from 'dva/router';

import {Picker, List,} from 'antd-mobile';
import {createForm} from 'rc-form';

class PickerComponent extends Component {

  constructor(props) {
    super(props);
    this.state = {
      value:''
    }
  }

  pickerClick = (v) =>{
    this.setState({
      value:v
    })
  this.props.onSave(v)
  }

  componentWillReceiveProps(newProps){
    this.state.value = newProps.displayDefaults ? newProps.displayDefaults : [];
  }

  render() {
    const {data,title,displayNull,displayDefaults,header,onSave} = this.props;

    return (
          <Picker
            data={data}
            title={title}
            cascade={false}
            extra={this.state.value?displayNull:displayDefaults}
            value={this.state.value}
            onChange={(v) => this.pickerClick(v)}
            >
            <List.Item arrow="horizontal">{header}</List.Item>
          </Picker>
    );
  }

}

const PickerComponentWrapper = createForm()(PickerComponent);

export default connect()(PickerComponentWrapper);
